package com.mmlc.meimei.lichengkongjian.mine;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.androidnetframe.httputil.BaseRequestFilterLayer;
import com.androidnetframe.responsejavabean.RequestError;
import com.mmlc.inter.InterActivity;
import com.mmlc.meimei.lichengkongjian.R;
import com.mmlc.network.filter.MyVipRequestFilter;
import com.mmlc.network.responsebean.CardInfoResponseBean;
import com.mmlc.utils.XUtils;

public class MyVipActivity extends InterActivity {

    private ImageView iv_back;
    private ImageView iv_set;
    private TextView tv_title;

    private TextView tv_vip_name,tv_vip_num,tv_all_points,tv_used_points,tv_points_balance,tv_view_details
            ,tv_qr_time,tv_rebuild;
    private ImageView iv_qr_code;
    private CardInfoResponseBean.DataBean mData;

    @Override
    protected int initContentView() {
        return R.layout.activity_my_vip;
    }

    @Override
    protected void initView() {
        iv_back = (ImageView) findViewById(R.id.iv_back);
        iv_set = (ImageView) findViewById(R.id.iv_set);
        tv_title = (TextView) findViewById(R.id.tv_title);

        tv_vip_name = (TextView) findViewById(R.id.tv_vip_name);
        tv_vip_num = (TextView) findViewById(R.id.tv_vip_num);
        tv_all_points = (TextView) findViewById(R.id.tv_all_points);
        tv_used_points = (TextView) findViewById(R.id.tv_used_points);
        tv_points_balance = (TextView) findViewById(R.id.tv_points_balance);
        tv_view_details = (TextView) findViewById(R.id.tv_view_details);
        tv_qr_time = (TextView) findViewById(R.id.tv_qr_time);
        tv_rebuild = (TextView) findViewById(R.id.tv_rebuild);

        iv_qr_code = (ImageView) findViewById(R.id.iv_qr_code);

        tv_title.setText("我的VIP");
        iv_set.setVisibility(View.GONE);
    }

    @Override
    protected void initEvent() {
        iv_back.setOnClickListener(this);
        tv_view_details.setOnClickListener(this);
        tv_rebuild.setOnClickListener(this);
    }

    @Override
    protected void initInfo() {
        MyVipRequestFilter filter = new MyVipRequestFilter(this);
        filter.sendRequest(new BaseRequestFilterLayer.AccessResultFromFilter<CardInfoResponseBean>() {
            @Override
            public void onSuccess(CardInfoResponseBean result) {
                if(result != null && result.getData() != null){
                    mData = result.getData();
                    showData(result.getData());
                }
            }

            @Override
            public void onFailed(View errorLayout, RequestError serverError, int failedType) {

            }
        });
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()){
            case R.id.tv_view_details:
                Intent intent = new Intent(MyVipActivity.this,MyScoreActivity.class);
                intent.putExtra("score",mData.score_sy);
                startActivity(intent);
                break;
            case R.id.tv_rebuild:

                break;
            case R.id.iv_back:
                finish();
                break;
        }
    }

    private void showData(CardInfoResponseBean.DataBean bean){
        tv_vip_name.setText(bean.name);
        tv_vip_num.setText(bean.card_num);
        tv_all_points.setText(bean.score_xf);
        tv_used_points.setText(bean.score_use);
        tv_points_balance.setText(bean.score_sy);
//        tv_qr_time.setText("此二维码有效时间为：");
        XUtils.image(iv_qr_code, bean.qrimg);
    }

}
